- Tools
- Markdown Documentation Guides
- Quarto
- Sidebar Optimization
Sidebar Page Transition Optimization
Dario Airoldi
January 30, 2025
December 29, 2025
Sidebar Page Transition Optimization
📋 Table of Contents
Problem Solved
The sidebar was performing full restoration (taking 2-5 seconds) every time the user navigated between pages, causing a poor user experience with:
- ❌ Menu closing and reopening on every page switch
- ❌ 2-5 second delay before manual interactions were possible
- ❌ Full refresh restoration process for simple navigation
Solution Implemented
🔍 Smart Page Transition Detection
- Initial Page Load: Full, careful restoration (25ms intervals)
- Page Transitions: Ultra-fast restoration (5ms intervals)
- Detection Logic: Uses sessionStorage, URL changes, and navigation click tracking
⚡ Optimized Restoration Modes
For Initial Page Loads (First Visit)
- Progressive restoration: 25ms intervals between sections
- Smooth animations: Full Bootstrap animations enabled
- Safety timeout: 2 seconds maximum
- Visual feedback: Full console logging
For Page Transitions (Navigation)
- Ultra-fast restoration: 5ms intervals between sections
- Direct DOM manipulation: Bypasses slow Bootstrap animations
- Quick completion: 50ms final delay vs 100ms
- Visual indicator: “⚡ Restoring menu…” notification
- Safety timeout: 1 second maximum
📊 Performance Improvements
| Scenario | Before | After | Improvement |
|---|---|---|---|
| Initial Load | 2-5s | 1-2s | ~60% faster |
| Page Transitions | 2-5s | 0.2-0.5s | ~90% faster |
| User Interaction Block | 2-5s | 0.2-0.5s | ~90% faster |
🛡️ Reliability Features
- Preemptive State Saving
- Saves state when navigation links are clicked
- Saves state on page unload
- Reduces restoration dependency
- Smart Detection
- Tracks navigation clicks with
pending_navigationflag - Monitors URL changes and timing
- Differentiates between refresh and navigation
- Tracks navigation clicks with
- Error Recovery
- Safety timeouts force-enable interactions
- Graceful fallbacks for detection failures
- Comprehensive error logging
User Experience
✅ What Users Now Experience
- Instant menu restoration on page navigation (< 0.5s)
- No blocking of manual interactions during restoration
- Smooth first load with proper animation timing
- Visual feedback for page transitions
🎯 Technical Implementation
// Detection determines restoration mode
const isPageTransition = detectPageTransition();
// Different timing for each scenario
const EXPAND_DELAY_INCREMENT = isPageTransition ? 5 : 25; // ms
const SAFETY_TIMEOUT = isPageTransition ? 1000 : 2000; // ms
const COMPLETION_DELAY = isPageTransition ? 50 : 100; // ms
// Different expansion methods
if (isPageTransition) {
expandSectionFast(section, sectionName); // Direct DOM
} else {
expandSectionSmoothly(section, sectionName); // Bootstrap animations
}The solution maintains full compatibility with existing functionality while dramatically improving the user experience during page navigation.
📚 References
Related Articles in This Series
How Quarto Sidebar Works [📘 Official]
Detailed guide to Quarto’s sidebar layout architecture and state management. Understanding the sidebar architecture is essential background for comprehending the optimization techniques used in this article. Reference when working with sidebar customization.
Navigation Workflow [📘 Official]
Complete navigation workflow guide covering automated navigation.json generation and development workflows. Reference when implementing navigation features or troubleshooting navigation issues.
Build Optimization [📘 Official]
Comprehensive performance optimization strategies for Quarto sites. Reference for understanding broader performance optimization context and complementary optimization techniques.
Official Documentation
Bootstrap Collapse Documentation [📘 Official]
Official Bootstrap documentation for collapse component used in Quarto sidebar. Understanding Bootstrap collapse behavior is essential for implementing custom sidebar animations. Reference when working with Bootstrap-based UI components.
Web Performance Best Practices [📗 Verified Community]
Google’s comprehensive guide to web performance optimization. Provides broader context for performance optimization techniques used in this implementation. Reference when evaluating performance improvements.
Related Articles
For more context on Quarto navigation and sidebar functionality:
- 06-sidebar-layout.md - Understanding sidebar layout architecture
- 06-navigation-workflow.md - Complete navigation workflow guide
- 07-build-optimization.md - General performance optimization